#include "core/log_entry.hpp"
#include <nlohmann/json.hpp> // 在这里包含完整头文件

// 默认构造函数中，要初始化指针
LogEntry::LogEntry() : context(std::make_unique<nlohmann::json>()) {}

// 析构函数必须有函数体（即使是空的），以确保编译器在此处看到 nlohmann::json 的完整定义
LogEntry::~LogEntry() = default; 

// 拷贝构造函数需要深拷贝
LogEntry::LogEntry(const LogEntry& other) 
    : level(other.level), 
      message(other.message), 
      timestamp(other.timestamp),
      // 如果 other.context 非空，则深拷贝
      context(other.context ? std::make_unique<nlohmann::json>(*other.context) : nullptr),
      trace_id(other.trace_id),
      span_id(other.span_id) {}

// 移动构造函数可以保持 noexcept
LogEntry::LogEntry(LogEntry&& other) noexcept = default;

// 拷贝赋值运算符
LogEntry& LogEntry::operator=(const LogEntry& other) {
    if (this != &other) {
        level = other.level;
        message = other.message;
        timestamp = other.timestamp;
        trace_id = other.trace_id;
        span_id = other.span_id;
        // 深拷贝 context
        context = other.context ? std::make_unique<nlohmann::json>(*other.context) : nullptr;
    }
    return *this;
}

// 移动赋值运算符
LogEntry& LogEntry::operator=(LogEntry&& other) noexcept = default;
